package com.nit.lab.controller;

import com.nit.lab.dto.DtoLoginUser;
import com.nit.lab.dto.DtoSysFile;
import com.nit.lab.dto.DtohisOrder;
import com.nit.lab.dto.utils.DtoAjaxMsg;
import com.nit.lab.dto.utils.DtoDataTable;
import com.nit.lab.dto.utils.DtoDataTableReturn;
import com.nit.lab.service.FileService;
import com.nit.lab.service.HisOrderService;
import com.nit.lab.utils.SystemConstants;
import org.jboss.logging.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

/**
 * Created by CYT on 2017/12/7.
 */
@Controller
@Scope("prototype")
@RequestMapping("/HisOrderController")
public class HisOrderController {
    private static Logger log = Logger.getLogger(UserController.class.getClass());
    @Resource
    private HisOrderService hisOrderService;

    @ResponseBody
    @RequestMapping("/getHisOrder")
    public DtoDataTableReturn getHisOrderFile(DtoDataTable dtoDataTable, Integer sessionId, Integer actorId) {
        DtoDataTableReturn jsonList = null;
        Integer pre;
        try {
            if (sessionId == null) {
                pre = -1;
            } else {
                pre = sessionId;/*帐号*/
            }
            Integer count = hisOrderService.getHisOrderDataTableCount(dtoDataTable.getSearch(), pre, actorId);
            List<DtohisOrder> dtohisOrders = hisOrderService.getHisOrderDataTable(dtoDataTable, pre, actorId);
            jsonList = new DtoDataTableReturn(dtoDataTable.getDraw(), count, count, dtohisOrders);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
        return jsonList;
    }
    /*@RequestMapping(value = "/insertEvaluate")
    @ResponseBody
    public DtoAjaxMsg insertUserInfo(DtoLoginUser dtoLoginUser) throws IOException {
        DtoAjaxMsg dtoAjaxMsg = new DtoAjaxMsg();
        try {
            Integer result = hisOrderService.insertEvaluate(dtoLoginUser);
            if (result > SystemConstants.Insert_Success) {
                dtoAjaxMsg.setAjaxInfo(SystemConstants.INTERFACE_SUCCESS);
                //dtoAjaxMsg.ajaxInfo 为 string类型。
                //SystemConstants.INTERFACE_SUCCESS = "Success"
            } else {
                dtoAjaxMsg.setAjaxInfo(SystemConstants.INTERFACE_FAILUER);
            }
        } catch (Exception e) {
            log.error(e.getMessage());
            dtoAjaxMsg.setAjaxInfo(SystemConstants.INTERFACE_FAILUER);
        }
        System.out.println("dtoAjaxMsg:" + dtoAjaxMsg.getAjaxInfo());
        return dtoAjaxMsg;
        //dtoAjaxMsg中有2个变量：String类的ajaxInfo 和 Object类的ajaxObject;
    }*/

    @ResponseBody
    @RequestMapping(value = "/evaluateOrder")
    public DtoAjaxMsg evaluateOrder(Integer orderId, Integer evaluate) throws Exception {
        DtoAjaxMsg dtoAjaxMsg = new DtoAjaxMsg();
        if (hisOrderService.evaluate(orderId, evaluate) != 0) {
            dtoAjaxMsg.setAjaxInfo("Success");
        } else {
            dtoAjaxMsg.setAjaxInfo("Falis");
        }
        return dtoAjaxMsg;
    }
}
